var PurchaseTemplate = function () {
  var explainText = '说明：表格数据会下面选择的列数据进行合并，选择的列的数据完全相同就会合并为一条数据，如果都不选就不合并数据';
  var template = /* html */ `
    <div class="purchase-template common-template-setting" :class="{'is-dragging':hasDrag}" v-loading.fullscreen.lock="loading">
      <div v-if="customTemplate" class="has-custom-template">
        <div class="no-data">
          <div>已经有自定义的采购单模板，不能再设置该通用模板</div>
        </div>
      </div>
      <order-template-setting v-else-if="templateConfig!==null" :config="templateConfig" :type="type" @save-click="saveTemplate">
        <template slot="table">
          <div class="setting-form-item clearfix" v-if="isPayUser">
            <label style="float:none;width:100%;text-align:left;">订单采购单根据下面哪些数据计算小计(只有表格里显示小计时有效)</label>
            <div style="float:none">
              <el-checkbox-group v-model="templateConfig.orderGroup">
                <el-checkbox v-for="orderGroup in orderGroupList" :key="orderGroup.field" :label="orderGroup.field">
                  {{orderGroup.label}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <label style="float:none;width:100%;text-align:left;">库存采购单根据下面哪些数据计算小计(只有表格里显示小计时有效)</label>
            <div style="float:none">
              <el-checkbox-group v-model="templateConfig.warehouseGroup">
                <el-checkbox v-for="warehouseGroup in warehouseGroupList" :key="warehouseGroup.field" :label="warehouseGroup.field">
                  {{warehouseGroup.label}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </div>
          <div class="setting-form-item clearfix" v-if="isPayUser">
            <label style="float:none;width:100%;text-align:left;">订单采购单列设置</label>
            <div style="float:none">
              <table-column-setting :setting="templateConfig" column-field="orderPurchaseColumns" :column-dropdown="ordertPurchaseColumnDropdown">
              </table-column-setting>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <label style="float:none;width:100%;text-align:left;">库存采购单列设置</label>
            <div style="float:none">
              <table-column-setting :setting="templateConfig" column-field="warehousePurchaseColumns" :column-dropdown="warehousePurchaseColumnDropdown">
              </table-column-setting>
            </div>
          </div>
        </template>
        <template slot="other-prepend">
          <div class="setting-form-item clearfix">
            <div>
              <el-checkbox v-model="templateConfig.hasSumBtn">显示表格切换是否显示采购量小计按钮</el-checkbox>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <div>
              <el-checkbox v-model="templateConfig.showOrderTableSum" v-if="isPayUser">订单采购单表格默认是否显示采购量小计</el-checkbox>
              <el-checkbox v-model="templateConfig.showWarehouseTableSum">库存采购单表格默认是否显示采购量小计</el-checkbox>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <div>
              <el-checkbox v-model="templateConfig.hasImgBtn">显示表格切换是否显示物料图片按钮</el-checkbox>
              <el-checkbox v-model="templateConfig.showTableImg">表格默认是否显示物料图片</el-checkbox>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <div>
              <el-checkbox v-model="templateConfig.showEmail">上面的表格是否显示公司的邮箱地址</el-checkbox>
            </div>
          </div>
          <div class="setting-form-item clearfix">
            <div>
              <el-checkbox v-model="templateConfig.addRowRemark">表格新增插入物料行备注功能</el-checkbox>
              <el-checkbox v-model="templateConfig.addDelRow">表格新增删除行物料数据功能</el-checkbox>
            </div>
          </div>
        </template>
        <template slot="table-before">
          <form-group group-title="表格数据合并设置" style="margin-top:10px;">
            <div style="float:none;color:#ff0000">${explainText}</div>
            <div style="float:none" v-if="isPayUser">
              <div style="margin-bottom:5px">订单采购单</div>
              <el-checkbox-group v-model="templateConfig.orderMerge">
                <el-checkbox v-for="orderMerge in orderMergeList" :key="orderMerge.field" :label="orderMerge.field">
                  {{orderMerge.label}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
            <div style="float:none">
              <div style="margin-bottom:5px">库存采购单</div>
              <el-checkbox-group v-model="templateConfig.warehouseMerge">
                <el-checkbox v-for="warehouseMerge in warehouseMergeList" :key="warehouseMerge.field" :label="warehouseMerge.field">
                  {{warehouseMerge.label}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </form-group>
        </template>
      </order-template-setting>
    </div>
  `;

  return {
    mixins: [templateSettingMixin('purchaseOrder')],

    computed: {
      isPayUser: function () {
        var user = this.user;
        if (user === null) {
          return false;
        }
        return user.companyInfo.status === 1;
      }
    },

    data: function () {
      return {
        orderMergeList: [{
          field: 'orderId',
          label: '订单编号、客户型号、工厂型号'
        }, {
          field: 'materialCode',
          label: '物料名称、供应商、编号、规格'
        }, {
          field: 'price',
          label: '单价'
        }, {
          field: 'unit',
          label: '单位'
        }, {
          field: 'remark',
          label: '备注'
        }],
        warehouseMergeList: [{
          field: 'orderId',
          label: '订单编号、客户型号、工厂型号'
        }, {
          field: 'materialCode',
          label: '物料名称、供应商、编号、规格'
        }, {
          field: 'price',
          label: '单价'
        }, {
          field: 'unit',
          label: '单位'
        }, {
          field: 'remark',
          label: '备注'
        }],
        orderGroupList: [{
          field: 'orderId',
          label: '订单编号、客户型号、工厂型号'
        }, {
          field: 'materialCode',
          label: '物料名称、供应商、编号、规格'
        }, {
          field: 'price',
          label: '单价'
        }],
        warehouseGroupList: [{
          field: 'orderId',
          label: '订单编号、客户型号、工厂型号'
        }, {
          field: 'materialCode',
          label: '物料名称、供应商、编号、规格'
        }, {
          field: 'price',
          label: '单价'
        }]
      };
    },

    components: {
      FormGroup: FormGroup
    },

    template: template
  };
}();
